﻿package mortal.game.view.guild.redPack
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class RedPackCreatePanel extends GSprite
    {
        private var _money:GTextInput;
        private var _redPackNum:GTextInput;
        private var _giveRedPackBtn:GLoadingButton;

        public function RedPackCreatePanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackTxt_9, 134, 110, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackTxt_7, 115, 165, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackTxt_6, 102, 352, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackTxt_8, 102, 382, this));
            this._money = UIFactory.gTextInput(215, 356, 100, 22, this);
            this._money.defaultText = "" + Language.getString(71269);
            this._money.textField.wordWrap = true;
            this._money.maxChars = 4;
            this._money.restrict = "0-9";
            this._money.textField.filters = [FilterConst.glowFilter];
            this._redPackNum = UIFactory.gTextInput(215, 386, 100, 22, this);
            this._redPackNum.text = "8";
            this._redPackNum.editable = false;
            this._redPackNum.textField.wordWrap = true;
            this._redPackNum.maxChars = 8;
            this._redPackNum.restrict = "0-9";
            this._redPackNum.textField.filters = [FilterConst.glowFilter];
            this._giveRedPackBtn = UIFactory.gLoadingButton(ResFileConst.FhbBtn, 144, 462, 130, 44, this);
            this._giveRedPackBtn.configEventListener(MouseEvent.CLICK, this.giveRedPack);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._giveRedPackBtn.dispose(param1);
            this._giveRedPackBtn = null;
            this._money.dispose(param1);
            this._money = null;
            this._redPackNum.dispose(param1);
            this._redPackNum = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function giveRedPack(event:MouseEvent) : void
        {
            if (!Cache.instance.guild.hasGuild)
            {
                return MsgManager.showRollTipsMsg("" + Language.getString(71270), MsgRollTipsType.msgRollTips3);
            }
            if (int(this._money.text) < 50 || int(this._money.text) > 1000)
            {
                return MsgManager.showRollTipsMsg("" + Language.getString(71271), MsgRollTipsType.msgRollTips3);
            }
            if (Cache.instance.redPackCache.selfRedEnvelopeInfo && Cache.instance.redPackCache.getRedPackMoney(1) > 0)
            {
                return MsgManager.showRollTipsMsg("" + Language.getString(71272), MsgRollTipsType.msgRollTips3);
            }
            if (!Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, int(this._money.text), null))
            {
                return MsgManager.showRollTipsMsg("" + Language.getString(71273), MsgRollTipsType.msgRollTips3);
            }
            GameProxy.guild.giveRedEnvelope(1, int(this._money.text), int(this._redPackNum.text));
            RedPacketWin.instance.hide();
            return;
        }// end function

    }
}
